package com.szq.day39.biz;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.szq.day39.Exception.BusinessException;
import com.szq.day39.dao.BlogDAO;
import com.szq.day39.entity.Blog;
@Service
public class BlogBiz {
	@Resource
	private BlogDAO dao;
	
	public List<Blog> findAll() throws BusinessException{
		try {
			return dao.findAll();
		} catch (Exception e) {
			e.printStackTrace();
			throw new BusinessException("E02B05");
		}
	}
	
	public Blog findById(int id) throws BusinessException {
		
		try {
			return dao.findById(id);
		} catch (Exception e) {
			e.printStackTrace();
			throw new BusinessException("E02B04");
		}
	}
	public void save(Blog blog) throws BusinessException{
		blog.setCreateTime(new Date());
		try {
			dao.save(blog);
		} catch (Exception e) {
			e.printStackTrace();
			throw new BusinessException("E02B01");
		}
	}
	public void delete(Blog blog) throws BusinessException {
		try {
			dao.delete(blog);
		} catch (Exception e) {
			e.printStackTrace();
			throw new BusinessException("E02B02");
		}
	}
	public void update(Blog blog) throws BusinessException{
		try {
			dao.update(blog);
		} catch (Exception e) {
			e.printStackTrace();
			throw new BusinessException("E02B03");
		}
	}

}
